home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / sun / volume1 / tooltool2.1c / part04 < prev    next >
Encoding:
Internet Message Format  |  1989-06-06  |  44.6 KB

  1. Path: uunet!cs.utexas.edu!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew
  2. From: mcgrew@dartagnan.rutgers.edu (Charles Mcgrew)
  3. Newsgroups: comp.sources.sun
  4. Subject: v01i023:  Tooltool - a suntools user interface builder, Part 04/13
  5. Message-ID: <Jun.7.00.13.04.1989.23536@dartagnan.rutgers.edu>
  6. Date: 7 Jun 89 04:13:08 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 1592
  9. Approved: mcgrew@aramis.rutgers.edu
  10.  
  11. Submitted-by: Chuck Musciano <chuck@trantor.harris-atd.com>
  12. Posting-number: Volume 1, Issue 23
  13. Archive-name: tooltool2.1c/part04
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 4 (of 13)."
  22. # Contents:  actions.c events.c misc.c tooltool.h
  23. # Wrapped by chuck@melmac on Thu Jun  1 10:39:29 1989
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'actions.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'actions.c'\"
  27. else
  28. echo shar: Extracting \"'actions.c'\" \(8513 characters\)
  29. sed "s/^X//" >'actions.c' <<'END_OF_FILE'
  30. X/************************************************************************/
  31. X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  32. X/*                                    */
  33. X/*    Permission to use, copy, modify, and distribute this software    */
  34. X/*    and its documentation for any purpose and without fee is    */
  35. X/*    hereby granted, provided that the above copyright notice    */
  36. X/*    appear in all copies and that both that copyright notice and    */
  37. X/*    this permission notice appear in supporting documentation, and    */
  38. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  39. X/*    used in advertising or publicity pertaining to distribution    */
  40. X/*    of the software without specific, written prior permission.    */
  41. X/*    Chuck Musciano and Harris Corporation make no representations    */
  42. X/*    about the suitability of this software for any purpose.  It is    */
  43. X/*    provided "as is" without express or implied warranty.        */
  44. X/*                                    */
  45. X/*    The sale of any product based wholely or in part upon the     */
  46. X/*    technology provided by tooltool is strictly forbidden without    */
  47. X/*    specific, prior written permission from Harris Corporation.    */
  48. X/*    Tooltool technology includes, but is not limited to, the source    */
  49. X/*    code, executable binary files, specification language, and    */
  50. X/*    sample specification files.                    */
  51. X/************************************************************************/
  52. X
  53. X#include    <stdio.h>
  54. X#include    <ctype.h>
  55. X
  56. X#include    "tooltool.h"
  57. X
  58. X#include    <suntool/tty.h>
  59. X
  60. XPUBLIC    Tty    tty;
  61. X
  62. X/************************************************************************/
  63. XPRIVATE    send_text(p)
  64. X
  65. Xchar    *p;
  66. X
  67. X{    int    len, sent;
  68. X
  69. X    if (tty)
  70. X       if (p && *p)
  71. X          for (len = strlen(p), sent = 0; sent < len; )
  72. X             sent += ttysw_input(tty, p + sent, len - sent);
  73. X}
  74. X
  75. X/************************************************************************/
  76. XPRIVATE    do_open()
  77. X
  78. X{    d_ptr    d;
  79. X
  80. X    window_set(tt_base_window->frame, FRAME_CLOSED, FALSE, 0);
  81. X    for (d = tt_base_window->next; d; d = d->next)
  82. X       if (d->is_open)
  83. X    window_set(d->frame, WIN_SHOW, TRUE, 0);
  84. X}
  85. X
  86. X/************************************************************************/
  87. XPRIVATE    do_close()
  88. X
  89. X{    d_ptr    d;
  90. X
  91. X    window_set(tt_base_window->frame, FRAME_CLOSED, TRUE, 0);
  92. X    for (d = tt_base_window->next; d; d = d->next)
  93. X       if (d->is_open)
  94. X    window_set(d->frame, WIN_SHOW, FALSE, 0);
  95. X}
  96. X
  97. X/************************************************************************/
  98. XEXPORT    a_ptr    tt_make_action(op, arg1, arg2, arg3, arg4)
  99. X
  100. Xint    op;
  101. Xe_ptr    arg1, arg2, arg3, arg4;
  102. X
  103. X{    a_ptr    a;
  104. X
  105. X    a = (a_ptr) safe_malloc(sizeof(a_data));
  106. X    a->next = NULL;
  107. X    switch (a->op = op) {
  108. X       case BEEP_OP     :
  109. X       case BREAK_OP    :
  110. X       case CLOSE_OP    :
  111. X       case CONTINUE_OP :
  112. X       case EXIT_OP     :
  113. X                     break;
  114. X       case DISPLAY_OP  : 
  115. X       case EXPR_OP     :
  116. X       case POPUP_OP    :
  117. X       case REMOVE_OP   :
  118. X       case SEND_OP     : a->expr = arg1;
  119. X                     break;
  120. X       case FOR_OP      : a->init = arg1;
  121. X                     a->expr = arg2;
  122. X                     a->term = arg3;
  123. X                     a->body = (a_ptr) arg4;
  124. X                     break;
  125. X       case IF_OP       : a->expr = arg1;
  126. X                     a->body = (a_ptr) arg2;
  127. X                     a->else_part = (a_ptr) arg3;
  128. X                     break;
  129. X       case WHILE_OP    : a->expr = arg1;
  130. X                     a->body = (a_ptr) arg2;
  131. X                     break;
  132. X       }
  133. X    return(a);
  134. X}
  135. X
  136. X/************************************************************************/
  137. XEXPORT    tt_do_action(a)
  138. X
  139. Xa_ptr    a;
  140. X
  141. X{    d_ptr    d;
  142. X    static    int    in_a_popup = FALSE, exit_pending = FALSE, close_pending = FALSE, open_pending = FALSE;
  143. X    static    int    break_pending = FALSE, continue_pending = FALSE;
  144. X
  145. X    tt_action_depth++;
  146. X    for ( ; a && !break_pending && !continue_pending; a = a->next) {
  147. X       tt_reset_emalloc();
  148. X       if (tt_timer_pending) {
  149. X          tt_timer_pending = FALSE;
  150. X          tt_do_action(tt_timer_action);
  151. X          }
  152. X       switch (a->op) {
  153. X          case BEEP_OP    : window_bell(tt_base_window->frame);
  154. X                       break;
  155. X          case BREAK_OP   : break_pending = TRUE;
  156. X                       break;
  157. X          case CLOSE_OP   : if (in_a_popup)
  158. X                         close_pending = TRUE;
  159. X                      else
  160. X                         do_close();
  161. X                       break;
  162. X          case CONTINUE_OP: continue_pending = TRUE;
  163. X                       break;
  164. X          case DISPLAY_OP : if (a->expr->symbol->kind == SYMBOL_SYMBOL)
  165. X                         abend("display: cannot display %s, which is not a dialog box or gadget", a->expr->symbol->name);
  166. X                      else if (a->expr->symbol->kind == SYMBOL_GADGET) {
  167. X                         if (a->expr->symbol->gadget == NULL)
  168. X                            abend("dialog box %s was never defined", a->expr->symbol->name);
  169. X                         panel_set(a->expr->symbol->gadget->panel_item, PANEL_SHOW_ITEM, TRUE, 0);
  170. X                         }
  171. X                      else {
  172. X                         if ((d = a->expr->symbol->dialog) == NULL)
  173. X                            abend("dialog box %s was never defined", a->expr->symbol->name);
  174. X                         window_set(d->frame, WIN_SHOW, TRUE, 0);
  175. X                         tt_do_action(d->open_action);
  176. X                         d->is_open = TRUE;
  177. X                         d->is_popup = FALSE;
  178. X                         }
  179. X                       break;
  180. X          case EXIT_OP    : if (in_a_popup)
  181. X                         exit_pending = TRUE;
  182. X                      else
  183. X                         exit(0);
  184. X                       break;
  185. X          case EXPR_OP    : tt_eval(a->expr);
  186. X                       break;
  187. X          case FOR_OP     : for (tt_eval(a->init); (int) tt_eval(a->expr)->number; tt_eval(a->term)) {
  188. X                         tt_do_action(a->body);
  189. X                         if (break_pending) {
  190. X                            break_pending = FALSE;
  191. X                            break;
  192. X                            }
  193. X                         if (continue_pending) {
  194. X                            continue_pending = FALSE;
  195. X                            continue;
  196. X                            }
  197. X                         }
  198. X                       break;
  199. X          case IF_OP      : tt_do_action(((int) tt_eval(a->expr)->number)? a->body : a->else_part);
  200. X                       break;
  201. X          case OPEN_OP    : if (in_a_popup)
  202. X                         open_pending = TRUE;
  203. X                      else
  204. X                         do_open();
  205. X                       break;
  206. X          case POPUP_OP   : if (a->expr->symbol->kind != SYMBOL_DIALOG)
  207. X                         abend("popup: %s is not a dialog box", a->expr->symbol->name);
  208. X                      else if ((d = a->expr->symbol->dialog) == NULL)
  209. X                         abend("dialog box %s was never defined", a->expr->symbol->name);
  210. X                      else if (d->is_open)
  211. X                         abend("popup: dialog box %s is already open", a->expr->symbol->name);
  212. X                      else if (in_a_popup)
  213. X                         abend("nested popup windows are not allowed");
  214. X                      d->is_open = TRUE;
  215. X                      d->is_popup = TRUE;
  216. X                      tt_do_action(d->open_action);
  217. X                      in_a_popup = TRUE;
  218. X                      window_loop(d->frame);
  219. X                      in_a_popup = FALSE;
  220. X                      tt_do_action(d->close_action);
  221. X                      d->is_open = FALSE;
  222. X                      d->is_popup = TRUE;
  223. X                      if (close_pending)
  224. X                         do_close();
  225. X                      if (open_pending)
  226. X                         do_open();
  227. X                      if (exit_pending)
  228. X                         exit(0);
  229. X                      close_pending = open_pending = exit_pending = FALSE;
  230. X                       break;
  231. X          case REMOVE_OP  : if (a->expr->symbol->kind == SYMBOL_SYMBOL)
  232. X                         abend("remove: cannot remove %s, which is not a dialog box or gadget", a->expr->symbol->name);
  233. X                      else if (a->expr->symbol->kind == SYMBOL_GADGET) {
  234. X                         if (a->expr->symbol->gadget == NULL)
  235. X                            abend("gadget %s was never defined", a->expr->symbol->name);
  236. X                         panel_set(a->expr->symbol->gadget->panel_item, PANEL_SHOW_ITEM, FALSE, 0);
  237. X                         }
  238. X                      else {
  239. X                         if ((d = a->expr->symbol->dialog) == NULL)
  240. X                            abend("dialog box %s was never defined", a->expr->symbol->name);
  241. X                         if (d->is_open)
  242. X                            if (d->is_popup)
  243. X                               window_return(0);
  244. X                            else {
  245. X                               window_set(d->frame, WIN_SHOW, FALSE, 0);
  246. X                               tt_do_action(d->close_action);
  247. X                               d->is_open = FALSE;
  248. X                               d->is_popup = FALSE;
  249. X                               }
  250. X                         }
  251. X                       break;
  252. X          case SEND_OP    : send_text(tt_string_of(tt_eval(a->expr)));
  253. X                       break;
  254. X          case WHILE_OP   : while ((int) tt_eval(a->expr)->number) {
  255. X                         tt_do_action(a->body);
  256. X                         if (break_pending) {
  257. X                            break_pending = FALSE;
  258. X                            break;
  259. X                            }
  260. X                         if (continue_pending) {
  261. X                            continue_pending = FALSE;
  262. X                            continue;
  263. X                            }
  264. X                         }
  265. X                       break;
  266. X          default          : abend("Internal error! Undefined action: %d", a->op);
  267. X          }
  268. X       }
  269. X    if (--tt_action_depth == 0) {
  270. X       if (continue_pending)
  271. X          abend("continue action used outside of a while or for action");
  272. X       break_pending = FALSE;
  273. X       }
  274. X}
  275. END_OF_FILE
  276. if test 8513 -ne `wc -c <'actions.c'`; then
  277.     echo shar: \"'actions.c'\" unpacked with wrong size!
  278. fi
  279. # end of 'actions.c'
  280. fi
  281. if test -f 'events.c' -a "${1}" != "-c" ; then 
  282.   echo shar: Will not clobber existing file \"'events.c'\"
  283. else
  284. echo shar: Extracting \"'events.c'\" \(10873 characters\)
  285. sed "s/^X//" >'events.c' <<'END_OF_FILE'
  286. X/************************************************************************/
  287. X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  288. X/*                                    */
  289. X/*    Permission to use, copy, modify, and distribute this software    */
  290. X/*    and its documentation for any purpose and without fee is    */
  291. X/*    hereby granted, provided that the above copyright notice    */
  292. X/*    appear in all copies and that both that copyright notice and    */
  293. X/*    this permission notice appear in supporting documentation, and    */
  294. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  295. X/*    used in advertising or publicity pertaining to distribution    */
  296. X/*    of the software without specific, written prior permission.    */
  297. X/*    Chuck Musciano and Harris Corporation make no representations    */
  298. X/*    about the suitability of this software for any purpose.  It is    */
  299. X/*    provided "as is" without express or implied warranty.        */
  300. X/*                                    */
  301. X/*    The sale of any product based wholely or in part upon the     */
  302. X/*    technology provided by tooltool is strictly forbidden without    */
  303. X/*    specific, prior written permission from Harris Corporation.    */
  304. X/*    Tooltool technology includes, but is not limited to, the source    */
  305. X/*    code, executable binary files, specification language, and    */
  306. X/*    sample specification files.                    */
  307. X/************************************************************************/
  308. X
  309. X#include    <stdio.h>
  310. X#include    <ctype.h>
  311. X
  312. X#include    "tooltool.h"
  313. X
  314. X#include    <suntool/tty.h>
  315. X
  316. XPUBLIC    Tty    tty;
  317. X
  318. XPRIVATE    int    value_invalid = FALSE;
  319. XPRIVATE    struct    itimerval    timer_int;
  320. X
  321. X/************************************************************************/
  322. X/* These routines deal with managing tooltool events            */
  323. X/************************************************************************/
  324. X
  325. X/************************************************************************/
  326. XPRIVATE    int    get_shifts(event)
  327. X
  328. XEvent    *event;
  329. X
  330. X{    int    shifts = 0;
  331. X
  332. X    if (event_shift_is_down(event))
  333. X       shifts += S_SHIFT;
  334. X    if (event_ctrl_is_down(event))
  335. X       shifts += S_CONTROL;
  336. X    if (event_meta_is_down(event))
  337. X       shifts += S_META;
  338. X    return(shifts);
  339. X}
  340. X
  341. X/************************************************************************/
  342. XPRIVATE    int    is_a_function_key(event)
  343. X
  344. XEvent    *event;
  345. X
  346. X{
  347. X    return(event_is_key_left(event) || event_is_key_top(event) || event_is_key_right(event));
  348. X}
  349. X
  350. X/************************************************************************/
  351. XPRIVATE    a_ptr    key_is_mapped(event)
  352. X
  353. XEvent    *event;
  354. X
  355. X{    int    set, key;
  356. X    a_ptr    a;
  357. X
  358. X    if (event_is_key_left(event)) {
  359. X       set = LEFT_KEY_SET;
  360. X       key = event_id(event) - KEY_LEFT(1);
  361. X       }
  362. X    else if (event_is_key_top(event)) {
  363. X       set = TOP_KEY_SET;
  364. X       key = event_id(event) - KEY_TOP(1);
  365. X       }
  366. X    else if (event_is_key_right(event)) {
  367. X       set = RIGHT_KEY_SET;
  368. X       key = event_id(event) - KEY_RIGHT(1);
  369. X       }
  370. X    else
  371. X       return(NULL);
  372. X    return(tt_func_keys[set][key][get_shifts(event)]);
  373. X}
  374. X
  375. X/************************************************************************/
  376. XPRIVATE    timer_proc()
  377. X
  378. X{
  379. X    if (tt_action_depth > 0)
  380. X       tt_timer_pending = TRUE;
  381. X    else
  382. X       tt_do_action(tt_timer_action);
  383. X}
  384. X
  385. X/************************************************************************/
  386. XEXPORT    Panel_setting    notify_proc(item, event)
  387. X
  388. XPanel_item    item;
  389. XEvent        *event;
  390. X
  391. X{    g_ptr    b;
  392. X    char    *p, buf[1024];
  393. X    int    i;
  394. X    cv_ptr    cv;
  395. X
  396. X    b = (g_ptr) panel_get(item, PANEL_CLIENT_DATA);
  397. X    if (b->kind == GADGET_BUTTON)
  398. X       tt_do_action(b->u.but.action[get_shifts(event)]);
  399. X    else if (b->kind == GADGET_TEXT) {
  400. X       if (index(b->u.tex.completion, event_id(event))) {
  401. X          p = (char *) panel_get(item, PANEL_VALUE);
  402. X          if (p = (char *) expand_filename(p))
  403. X             panel_set(item, PANEL_VALUE, p, 0);
  404. X          else
  405. X             window_bell(panel_get(item, PANEL_PARENT_PANEL));
  406. X          }
  407. X       else if (index(b->u.tex.trigger, event_id(event)))
  408. X          tt_do_action(b->u.tex.action);
  409. X       else if (event_id(event) == '\t')
  410. X          if (event_shift_is_down(event))
  411. X             panel_backup_caret(panel_get(item, PANEL_PARENT_PANEL));
  412. X          else
  413. X             panel_advance_caret(panel_get(item, PANEL_PARENT_PANEL));
  414. X       else if (!index(b->u.tex.ignore, event_id(event)))
  415. X          return(PANEL_INSERT);
  416. X       return(PANEL_NONE);
  417. X       }
  418. X    else if (b->kind == GADGET_CHOICE) {
  419. X       i = (int) panel_get(item, PANEL_VALUE);
  420. X       for (cv = b->u.cho.value; i && cv; i--, cv = cv->next)
  421. X          ;
  422. X       if (cv)
  423. X          tt_do_action(cv->action);
  424. X       }
  425. X    else if (b->kind == GADGET_SLIDER)
  426. X       tt_do_action(b->u.sli.action);
  427. X}
  428. X
  429. X/************************************************************************/
  430. XEXPORT    event_proc(item, event)
  431. X
  432. XPanel_item    item;
  433. XEvent        *event;
  434. X
  435. X{    char    c;
  436. X    g_ptr    b;
  437. X    a_ptr    a;
  438. X    d_ptr    d;
  439. X
  440. X    d = (d_ptr) window_get(panel_get(item, PANEL_PARENT_PANEL), WIN_CLIENT_DATA);
  441. X    b = (g_ptr) panel_get(item, PANEL_CLIENT_DATA);
  442. X    if (event_is_ascii(event) || event_is_meta(event))
  443. X       if (d->text_items_exist || tt_normal_off)
  444. X          if (b->kind == GADGET_TEXT && event_id(event) == '\t')
  445. X             notify_proc(item, event);
  446. X          else
  447. X             panel_default_handle_event(item, event);
  448. X       else {
  449. X          c = event_id(event);
  450. X          if (tty)
  451. X             ttysw_input(tty, &c, 1);
  452. X          }
  453. X    else if (is_a_function_key(event)) {
  454. X       if (a = key_is_mapped(event)) {
  455. X          if (event_is_down(event))
  456. X             tt_do_action(a);
  457. X          }
  458. X       else if (!tt_function_off)
  459. X          panel_default_handle_event(item, event);
  460. X       }
  461. X    else { /* handle each panel item type separately */
  462. X       if (b->kind == GADGET_BUTTON) {
  463. X          if (event_is_down(event) && event_id(event) == MS_RIGHT)
  464. X             tt_do_action(menu_show(b->u.but.menu, d->panel, event, 0));
  465. X          else
  466. X             panel_default_handle_event(item, event);
  467. X          }
  468. X       else if (b->kind == GADGET_MENU) {
  469. X          if (event_is_down(event) && event_id(event) == MS_RIGHT) {
  470. X             a = (a_ptr) menu_show(b->u.men.menu, d->panel, event, 0);
  471. X             if (value_invalid)
  472. X                value_invalid = FALSE;
  473. X             else
  474. X                tt_do_action(a);
  475. X             }
  476. X          else
  477. X             panel_default_handle_event(item, event);
  478. X          }
  479. X       else
  480. X          panel_default_handle_event(item, event);
  481. X       }
  482. X}
  483. X
  484. X/************************************************************************/
  485. XEXPORT    background_proc(panel, event)
  486. X
  487. XPanel    panel;
  488. XEvent    *event;
  489. X
  490. X{    char    c;
  491. X    a_ptr    a;
  492. X    d_ptr    d;
  493. X
  494. X    d = (d_ptr) window_get(panel, WIN_CLIENT_DATA);
  495. X    if (event_is_ascii(event) || event_is_meta(event))
  496. X       if (d->text_items_exist || tt_normal_off)
  497. X          panel_default_handle_event(panel, event);
  498. X       else {
  499. X          c = event_id(event);
  500. X          if (tty)
  501. X             ttysw_input(tty, &c, 1);
  502. X          }
  503. X    else if (is_a_function_key(event)) {
  504. X       if (a = key_is_mapped(event)) {
  505. X          if (event_is_down(event))
  506. X             tt_do_action(a);
  507. X          }
  508. X       else if (!tt_function_off)
  509. X          panel_default_handle_event(panel, event);
  510. X       }
  511. X    else
  512. X       panel_default_handle_event(panel, event);
  513. X}
  514. X
  515. X/************************************************************************/
  516. XPRIVATE    Notify_value    handle_mouse(button, shift, tty, event, arg, type)
  517. X
  518. Xint            button;
  519. Xint            shift;
  520. XTty            tty;
  521. XEvent            *event;
  522. XNotify_arg        arg;
  523. XNotify_event_type    type;
  524. X
  525. X{    int    x, y;
  526. X    a_ptr    a;
  527. X
  528. X    if (tt_mouse_chars) {
  529. X       x = event_x(event) / charwidth_of(tt_a_font) + tt_mouse_base;
  530. X       y = event_y(event) / charheight_of(tt_a_font) + tt_mouse_base;
  531. X       }
  532. X    else {
  533. X       x = event_x(event) + tt_mouse_base;
  534. X       y = event_y(event) + tt_mouse_base;
  535. X       }
  536. X    if (tt_mouse[button][shift].defined == MOUSE_UNDEFINED)
  537. X       return(notify_next_event_func(tty, event, arg, type));
  538. X    else if (tt_mouse[button][shift].defined == MOUSE_STRING)
  539. X       a = tt_mouse[button][shift].action;
  540. X    else if (tt_mouse[button][shift].defined == MOUSE_MENU) {
  541. X       a = (a_ptr) menu_show(tt_mouse[button][shift].menu, tty, event, 0);
  542. X       if (value_invalid) {
  543. X          a = NULL;
  544. X          value_invalid = FALSE;
  545. X          }
  546. X       }
  547. X    tt_mouse_x->value->number = x;
  548. X    tt_mouse_y->value->number = y;
  549. X    tt_do_action(a);
  550. X    return(NOTIFY_DONE);
  551. X}
  552. X
  553. X/************************************************************************/
  554. XEXPORT    Menu    ttymenu_proc(m, op)
  555. X
  556. XMenu    m;
  557. XMenu_generate    op;
  558. X
  559. X{
  560. X    value_invalid = TRUE;
  561. X    return(tt_ttymenu);
  562. X}
  563. X
  564. X/************************************************************************/
  565. XEXPORT    Notify_value    close_proc(win, event, arg, type)
  566. X
  567. XWindow    win;
  568. XEvent    *event;
  569. XNotify_arg    arg;
  570. XNotify_event_type    type;
  571. X
  572. X{    int    init_closed, curr_closed;
  573. X    Notify_value    value;
  574. X    d_ptr    d;
  575. X
  576. X    init_closed = (int) window_get(tt_base_window->frame, FRAME_CLOSED);
  577. X    value = notify_next_event_func(win, event, arg, type);
  578. X    curr_closed = (int) window_get(tt_base_window->frame, FRAME_CLOSED);
  579. X    if (init_closed != curr_closed)
  580. X       if (curr_closed) { /* transition from open to closed */
  581. X          tt_do_action(tt_base_window->close_action);
  582. X          for (d = tt_base_window->next; d; d = d->next)
  583. X             if (d->is_open)
  584. X                window_set(d->frame, WIN_SHOW, FALSE, 0);
  585. X          }
  586. X       else { /* transition from closed to open */
  587. X          tt_do_action(tt_base_window->open_action);
  588. X          for (d = tt_base_window->next; d; d = d->next)
  589. X             if (d->is_open)
  590. X                window_set(d->frame, WIN_SHOW, TRUE, 0);
  591. X          }
  592. X    return(value);
  593. X}
  594. X
  595. X/************************************************************************/
  596. XEXPORT    Notify_value    tty_handler(tty, event, arg, type)
  597. X
  598. XTty            tty;
  599. XEvent            *event;
  600. XNotify_arg        arg;
  601. XNotify_event_type    type;
  602. X
  603. X{    a_ptr    a;
  604. X
  605. X    if ((event_is_ascii(event) || event_is_meta(event)) && tt_normal_off)
  606. X       return(NOTIFY_DONE);
  607. X    else if (is_a_function_key(event)) {
  608. X       if (a = key_is_mapped(event)) {
  609. X          if (event_is_down(event))
  610. X             tt_do_action(a);
  611. X          }
  612. X       else if (!tt_function_off)
  613. X          return(close_proc(tty, event, arg, type));
  614. X       return(NOTIFY_DONE);
  615. X       }
  616. X    else if (event_id(event) == MS_LEFT && event_is_down(event))
  617. X       return(handle_mouse(MOUSE_LEFT, get_shifts(event), tty, event, arg, type));
  618. X    else if (event_id(event) == MS_MIDDLE && event_is_down(event))
  619. X       return(handle_mouse(MOUSE_CENTER, get_shifts(event), tty, event, arg, type));
  620. X    else if (event_id(event) == MS_RIGHT && event_is_down(event))
  621. X       return(handle_mouse(MOUSE_RIGHT, get_shifts(event), tty, event, arg, type));
  622. X    else
  623. X       return(close_proc(tty, event, arg, type));
  624. X}
  625. X
  626. X/************************************************************************/
  627. XEXPORT    Notify_value    tt_dialog_done(frame)
  628. X
  629. XFrame    frame;
  630. X
  631. X{    d_ptr    d;
  632. X
  633. X    d = (d_ptr) window_get(frame, WIN_CLIENT_DATA);
  634. X    d->is_open = FALSE;
  635. X    tt_do_action(d->close_action);
  636. X    window_set(frame, WIN_SHOW, FALSE, 0);
  637. X    return(NOTIFY_DONE);
  638. X}
  639. X
  640. X/************************************************************************/
  641. XEXPORT    tt_set_timer(sec, usec)
  642. X
  643. Xint    sec;
  644. Xint    usec;
  645. X
  646. X{
  647. X    if (sec != 0 || usec != 0) {
  648. X       timer_int.it_value.tv_sec = timer_int.it_interval.tv_sec = sec;
  649. X       timer_int.it_value.tv_usec = timer_int.it_interval.tv_usec = usec;
  650. X       notify_set_itimer_func(tt_base_window->frame, timer_proc, ITIMER_REAL, &timer_int, NULL);
  651. X       }
  652. X    else
  653. X       notify_set_itimer_func(tt_base_window->frame, timer_proc, ITIMER_REAL, NULL, NULL);
  654. X}
  655. END_OF_FILE
  656. if test 10873 -ne `wc -c <'events.c'`; then
  657.     echo shar: \"'events.c'\" unpacked with wrong size!
  658. fi
  659. # end of 'events.c'
  660. fi
  661. if test -f 'misc.c' -a "${1}" != "-c" ; then 
  662.   echo shar: Will not clobber existing file \"'misc.c'\"
  663. else
  664. echo shar: Extracting \"'misc.c'\" \(11000 characters\)
  665. sed "s/^X//" >'misc.c' <<'END_OF_FILE'
  666. X/************************************************************************/
  667. X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  668. X/*                                    */
  669. X/*    Permission to use, copy, modify, and distribute this software    */
  670. X/*    and its documentation for any purpose and without fee is    */
  671. X/*    hereby granted, provided that the above copyright notice    */
  672. X/*    appear in all copies and that both that copyright notice and    */
  673. X/*    this permission notice appear in supporting documentation, and    */
  674. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  675. X/*    used in advertising or publicity pertaining to distribution    */
  676. X/*    of the software without specific, written prior permission.    */
  677. X/*    Chuck Musciano and Harris Corporation make no representations    */
  678. X/*    about the suitability of this software for any purpose.  It is    */
  679. X/*    provided "as is" without express or implied warranty.        */
  680. X/*                                    */
  681. X/*    The sale of any product based wholely or in part upon the     */
  682. X/*    technology provided by tooltool is strictly forbidden without    */
  683. X/*    specific, prior written permission from Harris Corporation.    */
  684. X/*    Tooltool technology includes, but is not limited to, the source    */
  685. X/*    code, executable binary files, specification language, and    */
  686. X/*    sample specification files.                    */
  687. X/************************************************************************/
  688. X
  689. X#include    <stdio.h>
  690. X#include    <ctype.h>
  691. X#include    <sgtty.h>
  692. X#include    <pwd.h>
  693. X
  694. X#include    <sys/types.h>
  695. X#include    <sys/stat.h>
  696. X#include    <sys/dir.h>
  697. X#include    <sys/file.h>
  698. X
  699. X#include    <suntool/sunview.h>
  700. X#include    <suntool/icon_load.h>
  701. X
  702. X#include    "tooltool.h"
  703. X
  704. XPUBLIC    char    *index(), *rindex(), *getenv();
  705. X
  706. Xtypedef    struct    pc_rec    pc_data, *pc_ptr;
  707. Xtypedef    struct    fc_rec    fc_data, *fc_ptr;
  708. X
  709. Xstruct    pc_rec    {char    *path;
  710. X         struct    pixrect    *image;
  711. X         pc_ptr    next;
  712. X        };
  713. X
  714. Xstruct    fc_rec    {char    *path;
  715. X         struct    pixfont    *font;
  716. X         fc_ptr    next;
  717. X        };
  718. X
  719. XPRIVATE    pc_ptr    pix_cache = NULL;
  720. XPRIVATE    fc_ptr    font_cache = NULL;
  721. X
  722. X/************************************************************************/
  723. XEXPORT    char    *safe_malloc(size)
  724. X
  725. Xint    size;
  726. X
  727. X{    char    *p;
  728. X
  729. X    if (p = (char *) malloc(size))
  730. X       return(p);
  731. X    else
  732. X       abend("insufficient memory available");
  733. X}
  734. X
  735. X/************************************************************************/
  736. XEXPORT    safe_free(p)
  737. X
  738. Xchar    *p;
  739. X
  740. X{
  741. X    free(p);
  742. X}
  743. X
  744. X/************************************************************************/
  745. XEXPORT    tokenize(line, argc, argv, maxv)
  746. X
  747. Xchar    *line;
  748. Xint    *argc;
  749. Xchar    *argv[];
  750. Xint    maxv;
  751. X
  752. X{    char    *buf, match, *delimiters;
  753. X
  754. X    *argc = 0;
  755. X    buf = (char *) tt_emalloc(strlen(line) * 2 + 1);
  756. X    if ((delimiters = tt_string_of(tt_delimiters->value)) == NULL)
  757. X       delimiters = " \t\n\r\"'";
  758. X    while (*line && (*argc < (maxv - 1))) {
  759. X       while (*line && index(delimiters, *line))
  760. X          if (*line == '"' || *line == '\'')
  761. X             break;
  762. X          else
  763. X             line++;
  764. X       if (*line == '\0')
  765. X          break;
  766. X       argv[(*argc)++] = buf;
  767. X       if (index(delimiters, *line)) { /* scanning a quoted string */
  768. X          match = *line++; /* remove the quote mark */
  769. X          while (*line && (*line != match))
  770. X             *buf++ = *line++;
  771. X          if (*line)
  772. X             line++; /* wipe out quote mark */
  773. X          }
  774. X       else {
  775. X          while (*line && !index(delimiters, *line))
  776. X             *buf++ = *line++;
  777. X          }
  778. X       *buf++ = '\0';
  779. X       }
  780. X    *buf = '\0';
  781. X    argv[*argc] = (char *) 0;
  782. X}
  783. X
  784. X/************************************************************************/
  785. XEXPORT    struct    pixrect    *tt_load_icon(path)
  786. X
  787. Xchar    *path;
  788. X
  789. X{    char    msg[IL_ERRORMSG_SIZE];
  790. X    struct    pixrect    *p;
  791. X    FILE    *f;
  792. X    pc_ptr    pc;
  793. X
  794. X    for (pc = pix_cache; pc; pc = pc->next)
  795. X       if (strcmp(path, pc->path) == 0)
  796. X          return(pc->image);
  797. X    if ((p = icon_load_mpr(path, msg)) == NULL) { /* not in icon format */
  798. X       if ((f = fopen(path, "r")) == NULL)
  799. X          abend("could not open %s", path);
  800. X       if ((p = pr_load(f, NULL)) == NULL)
  801. X          abend("%s must be in either icon or raster file format", path);
  802. X       fclose(f);
  803. X       }
  804. X    pc = (pc_ptr) safe_malloc(sizeof(pc_data));
  805. X    pc->path = strsave(path);
  806. X    pc->image = p;
  807. X    pc->next = pix_cache;
  808. X    pix_cache = pc;
  809. X    return(p);
  810. X}
  811. X
  812. X/************************************************************************/
  813. XEXPORT    struct    pixfont    *tt_open_font(path)
  814. X
  815. Xchar    *path;
  816. X
  817. X{    struct    pixfont    *p;
  818. X    fc_ptr    pf;
  819. X
  820. X    for (pf = font_cache; pf; pf = pf->next)
  821. X       if (strcmp(path, pf->path) == 0)
  822. X          return(pf->font);
  823. X    if ((p = pf_open(path)) == NULL)
  824. X       abend("cannot open font: %s", path);
  825. X    pf = (fc_ptr) safe_malloc(sizeof(fc_data));
  826. X    pf->path = strsave(path);
  827. X    pf->font = p;
  828. X    pf->next = font_cache;
  829. X    font_cache = pf;
  830. X    return(p);
  831. X}
  832. X
  833. X/************************************************************************/
  834. XEXPORT    int    text_width(text, font)
  835. X
  836. Xunsigned    char    *text;
  837. Xstruct    pixfont    *font;
  838. X
  839. X{    int    width;
  840. X
  841. X    for (width = 0; *text; text++)
  842. X       width += font->pf_char[*text].pc_adv.x;
  843. X    return(width);
  844. X}
  845. X
  846. X/************************************************************************/
  847. XPRIVATE    char    *root_path(path)
  848. X
  849. Xchar    *path;
  850. X
  851. X{    char    *p;
  852. X
  853. X    if (p = rindex(path, '/'))
  854. X       if (p == path)
  855. X          p[1] = '\0';
  856. X       else
  857. X          *p = '\0';
  858. X    else
  859. X       *path = '\0';
  860. X    return(path);
  861. X}
  862. X
  863. X/************************************************************************/
  864. XPRIVATE    char    *last_node(path)
  865. X
  866. Xchar    *path;
  867. X
  868. X{    char    *p;
  869. X
  870. X    return((p = rindex(path, '/'))? p + 1 : path);
  871. X}
  872. X
  873. X/************************************************************************/
  874. XEXPORT    char    *expand_filename(path)
  875. X
  876. Xchar    *path;
  877. X
  878. X{    static    char    s[1024];
  879. X    char    pattern[1024], candidate[1024], *p,*q;
  880. X    DIR    *dir;
  881. X    struct    direct *dp;
  882. X    struct    passwd    *pw;
  883. X
  884. X    strcpy(s, path);
  885. X    if (*path == '~')
  886. X       if (path[1] == '/' || path[1] == '\0') {
  887. X          strcpy(s, getenv("HOME"));
  888. X          strcat(s, path + 1);
  889. X          }
  890. X       else {
  891. X          if ((p = index(path, '/')) != NULL)
  892. X             *p = '\0';
  893. X          if ((pw = getpwnam(path + 1)) != NULL) {
  894. X             strcpy(s, pw->pw_dir);
  895. X             if (p != NULL) {
  896. X                strcat(s, "/");
  897. X                strcat(s, p + 1);
  898. X                }
  899. X             }
  900. X          else
  901. X             return(NULL);
  902. X          }
  903. X    strcpy(pattern, last_node(s));
  904. X    if (*pattern == '\0')
  905. X       return(s);
  906. X    root_path(s);
  907. X    candidate[0] = '\0';
  908. X    if (*s == '\0')
  909. X       strcpy(s, ".");
  910. X    if ((dir = opendir(s)) == NULL) {
  911. X       strcpy(s, path);
  912. X       return(s);
  913. X       }
  914. X    while ((dp = readdir(dir)) != NULL)
  915. X       if (strncmp(dp->d_name, pattern, strlen(pattern)) == 0)
  916. X          if (*candidate == '\0')
  917. X             strcpy(candidate, dp->d_name);
  918. X          else {
  919. X             for (p = candidate, q = dp->d_name; *p == *q; p++, q++)
  920. X                ;
  921. X             *p = '\0';
  922. X             }
  923. X    closedir(dir);
  924. X    if (*candidate == '\0')
  925. X       return(NULL);
  926. X    else {
  927. X       if (strcmp(s, ".") == 0)
  928. X          *s = '\0';
  929. X       else if (s[strlen(s) - 1] != '/')
  930. X          strcat(s, "/");
  931. X       strcat(s, candidate);
  932. X       }
  933. X    return(s);
  934. X}
  935. X
  936. X/************************************************************************/
  937. XEXPORT    tt_construct_label(l)
  938. X
  939. Xl_ptr    l;
  940. X
  941. X{    struct    pr_prpos    where;
  942. X
  943. X    if (!l->is_icon && l->image == NULL) {
  944. X       l->image = mem_create(text_width(l->label, l->font), l->font->pf_defaultsize.y, 1);
  945. X       where.pr = l->image;
  946. X       where.pos.x = 0;
  947. X       where.pos.y = baseline_of(l->font);
  948. X       pf_text(where, PIX_SRC, l->font, l->label);
  949. X       }
  950. X}
  951. X
  952. X/************************************************************************/
  953. XEXPORT    l_ptr    tt_make_label(is_icon, label, font, image)
  954. X
  955. Xint    is_icon;
  956. Xchar    *label;
  957. XPixfont    *font;
  958. Xstruct    pixrect    *image;
  959. X
  960. X{    l_ptr    l;
  961. X
  962. X    l = (l_ptr) safe_malloc(sizeof(l_data));
  963. X    l->is_icon = is_icon;
  964. X    l->label = label;
  965. X    l->font = font;
  966. X    l->image = image;
  967. X    return(l);
  968. X}
  969. X
  970. X/************************************************************************/
  971. XEXPORT    d_ptr    tt_make_base_window()
  972. X
  973. X{    d_ptr    d;
  974. X
  975. X    d = (d_ptr) safe_malloc(sizeof(d_data));
  976. X    d->frame = NULL;
  977. X    d->panel = NULL;
  978. X    d->is_base_frame = FALSE;
  979. X    d->is_open = TRUE;
  980. X    d->is_popup = FALSE;
  981. X    d->rows = 24;
  982. X    d->columns = 80;
  983. X    d->win_x = -1;
  984. X    d->win_y = -1;
  985. X    d->is_chars = TRUE;
  986. X    d->g_align = NO_ALIGN;
  987. X    d->proportional = FALSE;
  988. X    d->justified = TRUE;
  989. X    d->text_items_exist = FALSE;
  990. X    d->gadget_pos = G_NOPOS;
  991. X    d->gadgets = NULL;
  992. X    d->label = NULL;
  993. X    d->open_action = NULL;
  994. X    d->close_action = NULL;
  995. X    d->g_font = tt_default_font;
  996. X    d->next = NULL;
  997. X    return(d);
  998. X}
  999. X
  1000. X/************************************************************************/
  1001. XEXPORT    abend(s1, s2, s3, s4, s5, s6, s7, s8, s9)
  1002. X
  1003. Xchar    *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9;
  1004. X
  1005. X{
  1006. X    fprintf(stderr, "%s: ", tt_program);
  1007. X    fprintf(stderr, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  1008. X    fprintf(stderr, "\n");
  1009. X    exit(1);
  1010. X}
  1011. X
  1012. X/************************************************************************/
  1013. XEXPORT    int    tt_is_number(s)
  1014. X
  1015. Xregister    char    *s;
  1016. X
  1017. X{    register    int    saw_digit = FALSE;
  1018. X
  1019. X    if (*s == '-' || *s == '+')
  1020. X       s++;
  1021. X    for ( ; isdigit(*s); s++)
  1022. X       saw_digit = TRUE;
  1023. X    if (*s == '.')
  1024. X       for (s++; isdigit(*s); s++)
  1025. X          saw_digit = TRUE;
  1026. X    if (*s == 'e' || *s == 'E') {
  1027. X       if (*++s == '-' || *s == '+')
  1028. X          s++;
  1029. X       for ( ; isdigit(*s); s++)
  1030. X          saw_digit = TRUE;
  1031. X       }
  1032. X    return(saw_digit && *s == '\0');
  1033. X}
  1034. X
  1035. X/************************************************************************/
  1036. XEXPORT    int    tt_dict_compare(l, r)
  1037. X
  1038. Xchar    *l;
  1039. Xchar    *r;
  1040. X
  1041. X{    register    char    *p, *q;
  1042. X
  1043. X    for (p = l; isdigit(*p); p++)
  1044. X       ;
  1045. X    for (q = r; isdigit(*q); q++)
  1046. X       ;
  1047. X    if (*p || *q)
  1048. X       return(strcmp(l, r));
  1049. X    else
  1050. X       return(atoi(l) - atoi(r));
  1051. X}
  1052. X
  1053. X/************************************************************************/
  1054. XEXPORT    char    *tt_expand_ranges(s)
  1055. X
  1056. Xunsigned    char    *s;
  1057. X
  1058. X{    unsigned    char    *p, buf[1024];
  1059. X    int    c;
  1060. X
  1061. X    for (p = buf; *s; s) {
  1062. X       *p++ = *s++;
  1063. X       if (*s == '-' && *(s + 1) != '\0') {
  1064. X          for (c = *(p - 1), s++; c <= *s; )
  1065. X             *p++ = c++;
  1066. X          s++;
  1067. X          }
  1068. X       }
  1069. X    *p = '\0';
  1070. X    return(strsave(buf));
  1071. X}
  1072. X
  1073. X/************************************************************************/
  1074. XEXPORT    wait_for_window_size(width, height, timeout)
  1075. X
  1076. Xint    width;
  1077. Xint    height;
  1078. Xint    timeout; /* in milliseconds */
  1079. X
  1080. X{    struct    winsize    win;
  1081. X
  1082. X    if (width > 0 && height > 0)
  1083. X       do {
  1084. X          if (ioctl(fileno(stderr), TIOCGWINSZ, &win) < 0)
  1085. X             abend("could not obtain the window size");
  1086. X          usleep(50000);
  1087. X          } while ((win.ws_row != height || win.ws_col != width) && (timeout -= 50) > 0);
  1088. X}
  1089. X
  1090. X/************************************************************************/
  1091. XEXPORT    int    tt_perm_of(st)
  1092. X
  1093. Xstruct    stat    *st;
  1094. X
  1095. X{
  1096. X    if (getuid() == st->st_uid)
  1097. X       return((st->st_mode & 0700) >> 6);
  1098. X    else if (getgid() == st->st_gid)
  1099. X       return((st->st_mode & 070) >> 3);
  1100. X    else
  1101. X       return((st->st_mode & 07));
  1102. X}
  1103. X
  1104. X/************************************************************************/
  1105. XEXPORT    char    *tt_full_path_of(s, mode)
  1106. X
  1107. Xchar    *s;
  1108. Xint    mode;
  1109. X
  1110. X{    char    *path, *p, *q;
  1111. X    static    char    full_path[1024];
  1112. X    struct    stat    buf;
  1113. X
  1114. X    if (*s == '/')
  1115. X       return(s);
  1116. X    path = getenv("PATH");
  1117. X    for (p = path, q = full_path; TRUE; )
  1118. X       if (*p == ':' || *p == '\0') {
  1119. X          *q = '\0';
  1120. X          strcat(full_path, "/");
  1121. X          strcat(full_path, s);
  1122. X          if (stat(full_path, &buf) == 0 && ((buf.st_mode & S_IFMT) == S_IFREG) && access(full_path, mode) == 0)
  1123. X             return(full_path);
  1124. X          q = full_path;
  1125. X          if (*p++ == '\0')
  1126. X             return(s);
  1127. X          }
  1128. X       else
  1129. X          *q++ = *p++;
  1130. X}
  1131. END_OF_FILE
  1132. if test 11000 -ne `wc -c <'misc.c'`; then
  1133.     echo shar: \"'misc.c'\" unpacked with wrong size!
  1134. fi
  1135. # end of 'misc.c'
  1136. fi
  1137. if test -f 'tooltool.h' -a "${1}" != "-c" ; then 
  1138.   echo shar: Will not clobber existing file \"'tooltool.h'\"
  1139. else
  1140. echo shar: Extracting \"'tooltool.h'\" \(10629 characters\)
  1141. sed "s/^X//" >'tooltool.h' <<'END_OF_FILE'
  1142. X/************************************************************************/
  1143. X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  1144. X/*                                    */
  1145. X/*    Permission to use, copy, modify, and distribute this software    */
  1146. X/*    and its documentation for any purpose and without fee is    */
  1147. X/*    hereby granted, provided that the above copyright notice    */
  1148. X/*    appear in all copies and that both that copyright notice and    */
  1149. X/*    this permission notice appear in supporting documentation, and    */
  1150. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  1151. X/*    used in advertising or publicity pertaining to distribution    */
  1152. X/*    of the software without specific, written prior permission.    */
  1153. X/*    Chuck Musciano and Harris Corporation make no representations    */
  1154. X/*    about the suitability of this software for any purpose.  It is    */
  1155. X/*    provided "as is" without express or implied warranty.        */
  1156. X/*                                    */
  1157. X/*    The sale of any product based wholely or in part upon the     */
  1158. X/*    technology provided by tooltool is strictly forbidden without    */
  1159. X/*    specific, prior written permission from Harris Corporation.    */
  1160. X/*    Tooltool technology includes, but is not limited to, the source    */
  1161. X/*    code, executable binary files, specification language, and    */
  1162. X/*    sample specification files.                    */
  1163. X/************************************************************************/
  1164. X
  1165. X
  1166. X#include    <suntool/sunview.h>
  1167. X#include    <suntool/panel.h>
  1168. X
  1169. X/* Help delineate where routines are used and defined
  1170. X */
  1171. X#define        PUBLIC            extern
  1172. X#define        PRIVATE            static
  1173. X#define        EXPORT
  1174. X
  1175. X#define        strsave(s)        ((char *) strcpy((char *) safe_malloc(strlen(s) + 1), s))
  1176. X#define        estrsave(s)        ((char *) strcpy((char *) tt_emalloc(strlen(s) + 1), s))
  1177. X#define        baseline_of(f)        (-((f)->pf_char['0'].pc_home.y))
  1178. X#define        charwidth_of(f)        ((f)->pf_char['0'].pc_adv.x)
  1179. X#define        charheight_of(f)    ((f)->pf_defaultsize.y)
  1180. X#define        value_of(v)        ((v)->is_number? (v)->number : 0.0)
  1181. X
  1182. X/* The gadget position possibilities
  1183. X */
  1184. X#define        G_NOPOS            -1
  1185. X#define        G_TOP            0
  1186. X#define        G_BOTTOM        1
  1187. X#define        G_LEFT            2
  1188. X#define        G_RIGHT            3
  1189. X
  1190. X/* The shift states available for various function keys
  1191. X */
  1192. X#define        S_NORMAL        0
  1193. X#define        S_SHIFT            1
  1194. X#define        S_CONTROL        2
  1195. X#define        S_META            4
  1196. X#define        MAX_SHIFT_SETS        8
  1197. X
  1198. X/* The kind of gadgets we can create
  1199. X */
  1200. X#define        GADGET_BUTTON        0
  1201. X#define        GADGET_CHOICE        1
  1202. X#define        GADGET_LABEL        2
  1203. X#define        GADGET_MENU        3
  1204. X#define        GADGET_SLIDER        4
  1205. X#define        GADGET_TEXT        5
  1206. X
  1207. X/* Special functions that gadgets can perform
  1208. X */
  1209. X#define        BEEP_OP            0
  1210. X#define        BREAK_OP        1
  1211. X#define        CLOSE_OP        2
  1212. X#define        CONTINUE_OP        3
  1213. X#define        DISPLAY_OP        4
  1214. X#define        EXIT_OP            5
  1215. X#define        EXPR_OP            6
  1216. X#define        FOR_OP            7
  1217. X#define        IF_OP            8
  1218. X#define        OPEN_OP            9
  1219. X#define        POPUP_OP        10
  1220. X#define        REMOVE_OP        11
  1221. X#define        SEND_OP            12
  1222. X#define        WHILE_OP        13
  1223. X
  1224. X/* How labels are aligned with respect to each other
  1225. X */
  1226. X#define        NO_ALIGN        0
  1227. X#define        ALIGN_TOP        1
  1228. X#define        ALIGN_MIDDLE        2
  1229. X#define        ALIGN_BOTTOM        3
  1230. X
  1231. X/* The different function key sets on a Sun-3 keyboard
  1232. X */
  1233. X#define        LEFT_KEY_SET        0
  1234. X#define        TOP_KEY_SET        1
  1235. X#define        RIGHT_KEY_SET        2
  1236. X#define        MAX_KEY_SETS        3
  1237. X
  1238. X#define        MAX_FUNC_KEYS        15
  1239. X
  1240. X/* Mouse buttons
  1241. X */
  1242. X#define        MOUSE_LEFT        0
  1243. X#define        MOUSE_CENTER        1
  1244. X#define        MOUSE_RIGHT        2
  1245. X
  1246. X#define        MAX_MOUSE_BUTTONS    3
  1247. X
  1248. X/* The functions a mouse key can perform
  1249. X */
  1250. X#define        MOUSE_UNDEFINED        0
  1251. X#define        MOUSE_STRING        1
  1252. X#define        MOUSE_MENU        2
  1253. X
  1254. X/* The ways a choice gadget can be laid out
  1255. X */
  1256. X#define        CHOICE_CURRENT        0
  1257. X#define        CHOICE_CYCLE        1
  1258. X#define        CHOICE_HORIZONTAL    2
  1259. X#define        CHOICE_VERTICAL        3
  1260. X
  1261. X/* The kinds of symbols a user can define
  1262. X */
  1263. X#define        SYMBOL_SYMBOL        0
  1264. X#define        SYMBOL_GADGET        1
  1265. X#define        SYMBOL_DIALOG        2
  1266. X
  1267. X/* Various expression operators
  1268. X */
  1269. X#define        E_AND            0
  1270. X#define        E_ARRAY_REF        1
  1271. X#define        E_ASSIGN_AND        2
  1272. X#define        E_ASSIGN_DIVIDE        3
  1273. X#define        E_ASSIGN_MINUS        4
  1274. X#define        E_ASSIGN_MODULO        5
  1275. X#define        E_ASSIGN_OR        6
  1276. X#define        E_ASSIGN_PLUS        7
  1277. X#define        E_ASSIGN_TIMES        8
  1278. X#define        E_ASSIGN_XOR        9
  1279. X#define        E_ASSIGNMENT        10
  1280. X#define        E_COMMA            11
  1281. X#define        E_COMPLEMENT        12
  1282. X#define        E_DIVIDE        13
  1283. X#define        E_EQUAL            14
  1284. X#define        E_FUNC_ID        15
  1285. X#define        E_GREATER        16
  1286. X#define        E_GREATER_EQUAL        17
  1287. X#define        E_LEFT_SHIFT        18
  1288. X#define        E_LESS            19
  1289. X#define        E_LESS_EQUAL        20
  1290. X#define        E_LOGICAL_AND        21
  1291. X#define        E_LOGICAL_NOT        22
  1292. X#define        E_LOGICAL_OR        23
  1293. X#define        E_MINUS            24
  1294. X#define        E_MODULO        25
  1295. X#define        E_NOT_EQUAL        26
  1296. X#define        E_NUMBER        27
  1297. X#define        E_OR            28
  1298. X#define        E_PAREN            29
  1299. X#define        E_PLUS            30
  1300. X#define        E_POSTDECREMENT        31
  1301. X#define        E_POSTINCREMENT        32
  1302. X#define        E_PREDECREMENT        33
  1303. X#define        E_PREINCREMENT        34
  1304. X#define        E_QUESTION        35
  1305. X#define        E_RIGHT_SHIFT        36
  1306. X#define        E_STRING        37
  1307. X#define        E_SYMBOL        38
  1308. X#define        E_TIMES            39
  1309. X#define        E_UMINUS        40
  1310. X#define        E_XOR            41
  1311. X
  1312. X/* The kinds of values we can express.
  1313. X */
  1314. X#define        V_NOTHING        0
  1315. X#define        V_ARRAY            1
  1316. X#define        V_GADGET        2
  1317. X#define        V_NUMBER        4
  1318. X#define        V_INTERVAL        8
  1319. X
  1320. X#define        V_TYPES            (V_ARRAY | V_NUMBER)
  1321. X#define        V_SPECIAL        (V_GADGET | V_INTERVAL)
  1322. X
  1323. X#define        is_array(v)        ((v)->kind & V_ARRAY)
  1324. X#define        is_gadget(v)        ((v)->kind & V_GADGET)
  1325. X#define        is_number(v)        ((v)->kind & V_NUMBER)
  1326. X#define        is_interval(v)        ((v)->kind & V_INTERVAL)
  1327. X
  1328. X/* Special things used to beat a Suntools window size bug
  1329. X */
  1330. X#define        POLLING_MAGIC_NUMBER    "\001\002\003\004"
  1331. X#define        POLLING_TIME_OUT    20000 /* milliseconds */
  1332. X
  1333. X/* The data necessary to describe a label.  If "is_icon" is FALSE,
  1334. X * "label" holds the label text, and "font" holds the label font.
  1335. X * If TRUE, "image" holds the bitmap of the icon for the label.
  1336. X */
  1337. Xtypedef    struct    l_rec    l_data, *l_ptr;
  1338. X
  1339. Xstruct    l_rec    {int    is_icon;
  1340. X         char    *label;
  1341. X         struct    pixfont    *font;
  1342. X         struct    pixrect    *image;
  1343. X        };
  1344. X
  1345. X/* The data needed to describe a gadget.  "Kind" is one of 
  1346. X * GADGET_*, above, and indicates which portion of the union
  1347. X * is valid for this gadget.  "Image" contains the image bitmap
  1348. X * for buttons and menus, and labels if they are icons.  Sliders
  1349. X * and choices have their own, SunView-created, images.  For all
  1350. X * gadgets, "width" and "height" are set to reflect the image
  1351. X * bounding box, for gadget layout purposes.  The gadgets are 
  1352. X * linked together via "next".
  1353. X */
  1354. X
  1355. Xtypedef    struct    a_rec    a_data, *a_ptr;
  1356. Xtypedef    struct    cv_rec    cv_data, *cv_ptr;
  1357. Xtypedef struct    d_rec    d_data, *d_ptr;
  1358. Xtypedef    struct    e_rec    e_data, *e_ptr;
  1359. Xtypedef    struct    g_rec    g_data, *g_ptr;
  1360. Xtypedef    struct    s_rec    s_data, *s_ptr;
  1361. Xtypedef    struct    v_rec    v_data, *v_ptr;
  1362. X
  1363. Xtypedef    v_ptr    (*f_ptr)();
  1364. X
  1365. Xstruct    but_rec    {l_ptr    label[MAX_SHIFT_SETS];
  1366. X         a_ptr    action[MAX_SHIFT_SETS];
  1367. X         Menu    menu;
  1368. X        };
  1369. X
  1370. Xstruct    cv_rec    {l_ptr    label;
  1371. X         a_ptr    action;
  1372. X         cv_ptr    next;
  1373. X        };
  1374. X
  1375. Xstruct    cho_rec    {l_ptr    label;
  1376. X         int    mode;
  1377. X         int    ch_width;
  1378. X         int    ch_height;
  1379. X         l_ptr    mark;
  1380. X         l_ptr    nomark;
  1381. X         cv_ptr    value;
  1382. X        };
  1383. X
  1384. Xstruct    lab_rec    {l_ptr    label;
  1385. X        };
  1386. X
  1387. Xstruct    men_rec    {l_ptr    label;
  1388. X         Menu    menu;
  1389. X        };
  1390. X
  1391. Xstruct    sli_rec    {l_ptr    label;
  1392. X         int    minimum;
  1393. X         int    maximum;
  1394. X         int    initial;
  1395. X         int    value;
  1396. X         int    range;
  1397. X         int    width;
  1398. X         a_ptr    action;
  1399. X         struct    pixfont    *font;
  1400. X        };
  1401. X
  1402. Xstruct    tex_rec    {l_ptr    label;
  1403. X         char    *trigger;
  1404. X         char    *completion;
  1405. X         char    *ignore;
  1406. X         int    display_len;
  1407. X         int    retain_len;
  1408. X         a_ptr    action; 
  1409. X         struct    pixfont    *font;
  1410. X        };
  1411. X
  1412. Xstruct    g_rec    {int    kind;
  1413. X         char    *name;
  1414. X         Panel_item    panel_item;
  1415. X         struct    pixrect    *image;
  1416. X         int    width;
  1417. X         int    height;
  1418. X         int    x;
  1419. X         int    y;
  1420. X         g_ptr    next;
  1421. X         union    {struct    but_rec    but;
  1422. X              struct    cho_rec    cho;
  1423. X              struct    lab_rec    lab;
  1424. X              struct    men_rec    men;
  1425. X              struct    sli_rec    sli;
  1426. X              struct    tex_rec    tex;
  1427. X             } u;
  1428. X        };
  1429. X
  1430. X/* The data necessary to describe an action.
  1431. X */
  1432. Xstruct    a_rec    {int    op;
  1433. X         e_ptr    init;
  1434. X         e_ptr    expr;
  1435. X         e_ptr    term;
  1436. X         a_ptr    body;
  1437. X         a_ptr    else_part;
  1438. X         a_ptr    next;
  1439. X        };
  1440. X
  1441. X/* The data necessary to describe an expression
  1442. X */
  1443. Xstruct    e_rec    {int    op;
  1444. X         e_ptr    left;
  1445. X         e_ptr    right;
  1446. X         e_ptr    extra;
  1447. X         s_ptr    symbol;
  1448. X         char    *string;
  1449. X         double    value;
  1450. X         f_ptr    func;
  1451. X        };
  1452. X
  1453. X/* The data necessary to describe a value
  1454. X */
  1455. Xstruct    v_rec    {int    kind;
  1456. X         char    *str;    /* except when an array */
  1457. X         double    number;    /* if a number */
  1458. X         g_ptr    gadget;    /* if a gadget */
  1459. X         char    *index; /* array element index string */
  1460. X         v_ptr    value;    /* if an array */
  1461. X         v_ptr    left;    /* links for array element tree */
  1462. X         v_ptr    right;
  1463. X        };
  1464. X
  1465. X/* The data necessary to describe a symbol.
  1466. X */
  1467. Xstruct    s_rec    {int    kind;
  1468. X         char    *name;
  1469. X         g_ptr    gadget;        /* if a gadget */
  1470. X         d_ptr    dialog;        /* if a dialog */
  1471. X         v_ptr    value;        /* if a symbol */
  1472. X         s_ptr    left;
  1473. X         s_ptr    right;
  1474. X        };
  1475. X
  1476. X/* The data necessary to describe a panel
  1477. X */
  1478. Xstruct    d_rec    {Frame    frame;
  1479. X         Panel    panel;
  1480. X         int    is_base_frame;
  1481. X         int    is_open;
  1482. X         int    is_popup;
  1483. X         int    rows;
  1484. X         int    columns;
  1485. X         int    win_x;
  1486. X         int    win_y;
  1487. X         int    is_chars;
  1488. X         int    g_align;
  1489. X         int    proportional;
  1490. X         int    justified;
  1491. X         int    text_items_exist;
  1492. X         int    gadget_pos;
  1493. X         g_ptr    gadgets;
  1494. X         char    *label;
  1495. X         a_ptr    open_action;
  1496. X         a_ptr    close_action;
  1497. X         struct    pixfont    *g_font;
  1498. X         d_ptr    next;
  1499. X        };
  1500. X
  1501. X/* A mouse record holds operation to be performed by one mouse
  1502. X * button/shift-state combination.  "Defined" is one of 
  1503. X * MOUSE_{UNDEFINED,STRING,MENU}.  If MOUSE_STRING, "value" holds
  1504. X * the text to be transmitted.  If MOUSE_MENU, "menu" holds
  1505. X * the menu to be displayed.
  1506. X */
  1507. Xtypedef    struct    m_rec    m_data;
  1508. X
  1509. Xstruct    m_rec    {int    defined;
  1510. X         a_ptr    action;
  1511. X         Menu    menu;
  1512. X        };
  1513. X
  1514. X/* A variety of public data.  All globals begin with "tt_".
  1515. X */
  1516. XPUBLIC    a_ptr    tt_initial_action,
  1517. X        tt_timer_action,
  1518. X        tt_func_keys[MAX_KEY_SETS][MAX_FUNC_KEYS][MAX_SHIFT_SETS];
  1519. X
  1520. XPUBLIC    char    *tt_application,
  1521. X        *tt_curr_file,
  1522. X        *tt_icon,
  1523. X        *tt_program;
  1524. X
  1525. XPUBLIC    d_ptr    tt_base_window;
  1526. X
  1527. XPUBLIC    int    tt_mouse_base,
  1528. X        tt_mouse_chars,
  1529. X        tt_errors_occured,
  1530. X        tt_normal_off,
  1531. X        tt_function_off,
  1532. X        tt_action_depth,
  1533. X        tt_timer_pending;
  1534. X
  1535. XPUBLIC    l_ptr    tt_default_mark,
  1536. X        tt_default_nomark,
  1537. X        tt_default_cycle;
  1538. X
  1539. XPUBLIC    m_data    tt_mouse[MAX_MOUSE_BUTTONS][MAX_SHIFT_SETS];
  1540. X
  1541. XPUBLIC    Menu    tt_ttymenu;
  1542. X
  1543. XPUBLIC    struct    pixfont    *tt_default_font,
  1544. X            *tt_a_font;
  1545. X
  1546. XPUBLIC    struct    pixrect    tt_mark_image,
  1547. X            tt_nomark_image,
  1548. X            tt_cycle_image;
  1549. X
  1550. XPUBLIC    s_ptr    tt_mouse_x, tt_mouse_y, tt_delimiters;
  1551. X
  1552. X/* Public routines which do not return void.
  1553. X */
  1554. XPUBLIC    char    *safe_malloc();
  1555. XPUBLIC    struct    pixrect    *tt_load_icon();
  1556. XPUBLIC    struct    pixfont    *tt_open_font();
  1557. XPUBLIC    l_ptr    tt_make_label();
  1558. XPUBLIC    a_ptr    tt_make_action();
  1559. XPUBLIC    s_ptr    tt_find_symbol();
  1560. XPUBLIC    v_ptr    tt_get_value();
  1561. XPUBLIC    d_ptr    tt_make_base_window();
  1562. XPUBLIC    e_ptr    tt_make_expr();
  1563. XPUBLIC    v_ptr    tt_eval();
  1564. XPUBLIC    char    *tt_string_of();
  1565. XPUBLIC    f_ptr    tt_is_function();
  1566. XPUBLIC    char    *tt_emalloc();
  1567. XPUBLIC    v_ptr    tt_int_result();
  1568. XPUBLIC    v_ptr    tt_double_result();
  1569. XPUBLIC    v_ptr    tt_string_result();
  1570. XPUBLIC    v_ptr    tt_insert_array();
  1571. XPUBLIC    char    *tt_get_selection();
  1572. XPUBLIC    char    *tt_expand_ranges();
  1573. XPUBLIC    char    *tt_full_path_of();
  1574. END_OF_FILE
  1575. if test 10629 -ne `wc -c <'tooltool.h'`; then
  1576.     echo shar: \"'tooltool.h'\" unpacked with wrong size!
  1577. fi
  1578. # end of 'tooltool.h'
  1579. fi
  1580. echo shar: End of archive 4 \(of 13\).
  1581. cp /dev/null ark4isdone
  1582. MISSING=""
  1583. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do
  1584.     if test ! -f ark${I}isdone ; then
  1585.     MISSING="${MISSING} ${I}"
  1586.     fi
  1587. done
  1588. if test "${MISSING}" = "" ; then
  1589.     echo You have unpacked all 13 archives.
  1590.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1591. else
  1592.     echo You still need to unpack the following archives:
  1593.     echo "        " ${MISSING}
  1594. fi
  1595. ##  End of shell archive.
  1596. exit 0
  1597.  
  1598.  
  1599. Chuck Musciano            ARPA  : chuck@trantor.harris-atd.com
  1600. Harris Corporation         Usenet: ...!uunet!x102a!trantor!chuck
  1601. PO Box 37, MS 3A/1912        AT&T  : (407) 727-6131
  1602. Melbourne, FL 32902        FAX   : (407) 727-{5118,5227,4004}
  1603.